package com.zhoushihao.class0815;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Initialize {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int count = 0;
        boolean []isInitial = new boolean[n+1];
        isInitial[0] = true;
        for (int i = 0; i < k; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            if (x >= 1 && x <= n && y >= 0 && y <= n) {
                if (!isInitial[y]) {
                    count++;
                }
                isInitial[x]=true;
            }else {
                continue;
            }
        }
        System.out.println(count);
    }
}
